#
# class Light:
#     def __init__(self):
#         """
#         初始化方法：用于初始u啊实例（对象）属性
#         """
#         print(f"初始化函数执行了")
#         self.state="关"
#         self.colors=["红色","黄色","绿色"]
#         self.color_index=0
#         # self.color=self.colors[self.color_index]
#
#
#     def get_state(self):
#         return self.state
#     def change_state(self):
#         self.state="开"
#     def get_color(self):
#         return self.colors[self.color_index]
#     def change_color(self):
#         self.color_index+=1
#         print(self.color_index)
#         if self.color_index==3:
#             self.color_index=0
#     def __str__(self):
#         print(f"状态是{self.state},颜色是{self.color}")
#     def __del__(self):
#         print("析构函数执行")
#
#
# l1=Light()
# print(l1.get_state(),l1.get_color())
# l1.change_state()
# print(l1.get_state(),l1.get_color())
# l1.change_color()
# print(l1.get_state(),l1.get_color())
# l1.change_color()
# print(l1.get_state(),l1.get_color())
# l1.change_color()
# print(l1.get_state(),l1.get_color())
# l1.change_color()
# print(l1.get_state(),l1.get_color())



import random


class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age

    def get_name(self):
        return self.name

    def change_name(self, name):
        self.name = name

    def get_age(self):
        return self.age

    def change_age(self, age):
        self.age = age

    def __str__(self):
        return f"名字:{self.name}\t年龄：{self.age}"


class PersonMange:
    def __init__(self):
        self.persons = []

    def add_person(self, p):
        self.persons.append(p)

    def show_all_person(self):
        for p in self.persons:
            print(p)
    def show_down_age(self):
        self.persons.sort(key=lambda p:p.age,reverse=True)
        for p in self.persons:
            print(p)

# p1=Person("王",20)
# print(p1,p1.name,p1.age)
# p1.change_name("张")
# p1.change_age(30)
# print(p1,p1.get_name(),p1.get_age())

def main():
    pm = PersonMange()
    for i in range(3):
        p = Person(name=input("请输入名字"), age=random.randint(20, 30))
        pm.add_person(p)
    pm.show_all_person()
    pm.show_down_age()


main()
